package HOT100;

import java.util.Scanner;

/**
 * @author 是阿秋啊
 * @date 2022/09/24 17:53
 * 8
 * 0 0 1 0 0 1 0 0
 **/
public class meituan4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n =sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i< n; i++) {
            arr[i] = sc.nextInt();
        }
        int ret = help(arr,0,0,1);
        System.out.println(ret);
    }
    public static int help(int[] arr,int i,int sum,int lca) {
        if(i >= arr.length) {
            return sum;
        }
        while ( i < arr.length && arr[i] == 0) {
            sum = sum + lca;
            i++;
        }
        if (i < arr.length) {
            sum = Math.max(help(arr,++i,sum/2,++lca),help(arr,++i,sum,lca));
        }
        return sum;
    }
}